// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   change_ok.java

package ecommerce.design;

import include.get_sql.getInsertSql;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class change_ok extends HttpServlet
{

	public change_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		ValidataTag vt = new ValidataTag();
		counter count = new counter(dbApplication);
		getInsertSql getInsertSql = new getInsertSql();
		try
		{
			if (design_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String responsible_person_ID = "";
				String responsible_person_name = "";
				String fileKind_chain = request.getParameter("fileKind_chain");
				String chain_id = Divide1.getId(fileKind_chain);
				String chain_name = Divide1.getName(fileKind_chain);
				String sql2 = (new StringBuilder("select * from design_config_file_kind where file_id='")).append(chain_id).append("'").toString();
				String product_ID = request.getParameter("product_ID");
				String product_name = request.getParameter("product_name");
				String factory_name = request.getParameter("factory_name");
				String product_class = request.getParameter("product_class");
				String product_nick = request.getParameter("product_nick");
				String twin_name = request.getParameter("twin_name");
				String twin_ID = request.getParameter("twin_ID");
				String personal_unit = request.getParameter("personal_unit");
				String personal_value = request.getParameter("personal_value");
				if (personal_value.equals(""))
					personal_value = "0.00";
				personal_value = personal_value.replaceAll(",", "");
				String warranty = request.getParameter("warranty");
				String lifecycle = request.getParameter("lifecycle");
				String amount_unit = request.getParameter("amount_unit");
				String register = request.getParameter("register");
				String bodyc = new String(request.getParameter("provider_group").getBytes("UTF-8"), "UTF-8");
				String provider_group = exchange.toHtml(bodyc);
				String bodya = new String(request.getParameter("product_describe").getBytes("UTF-8"), "UTF-8");
				String product_describe = exchange.toHtml(bodya);
				String bodyb = new String(request.getParameter("promotion").getBytes("UTF-8"), "UTF-8");
				String promotion = exchange.toHtml(bodyb);
				String changer_ID = request.getParameter("changer_ID");
				String changer = request.getParameter("changer");
				String change_time = request.getParameter("change_time");
				String lately_change_time = request.getParameter("lately_change_time");
				String file_change_amount = request.getParameter("file_change_amount");
				int change_amount = Integer.parseInt(file_change_amount) + 1;
				String column_group = getInsertSql.sql((String)dbSession.getAttribute("unit_db_name"), "design_file");
				String list_price2 = request.getParameter("list_price");
				StringTokenizer tokenTO4 = new StringTokenizer(list_price2, ",");
				String list_price;
				String list_price1;
				for (list_price = ""; tokenTO4.hasMoreTokens(); list_price = (new StringBuilder(String.valueOf(list_price))).append(list_price1).toString())
					list_price1 = tokenTO4.nextToken();

				String cost_price2 = request.getParameter("cost_price");
				StringTokenizer tokenTO5 = new StringTokenizer(cost_price2, ",");
				String cost_price;
				String cost_price1;
				for (cost_price = ""; tokenTO5.hasMoreTokens(); cost_price = (new StringBuilder(String.valueOf(cost_price))).append(cost_price1).toString())
					cost_price1 = tokenTO5.nextToken();

				int n = 0;
				if (!validata.validata(list_price))
					n++;
				if (!validata.validata(cost_price))
					n++;
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID, "check_tag").equals("1"))
				{
					if (n == 0)
					{
						ResultSet rs2 = design_db.executeQuery(sql2);
						if (rs2.next())
						{
							try
							{
								String sqloo = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
								ResultSet rsoo = design_db.executeQuery(sqloo);
								if (rsoo.next())
								{
									String sqll = (new StringBuilder("insert into design_file_dig(CHAIN_ID,CHAIN_NAME,PRODUCT_ID,PRODUCT_NAME,PRODUCT_NICK,PRODUCT_CLASS,TYPE,AMOUNT_UNIT,PRODUCT_DESCRIBE,FACTORY_NAME,FACTORY_ID,PROVIDER_GROUP,PHOTO1,PHOTO2,WARRANTY,LIST_PRICE,COST_PRICE,REAL_COST_PRICE,LIFECYCLE,PERSONAL_UNIT,PERSONAL_VALUE,TWIN_NAME,TWIN_ID,REMARK,CHECK_TAG,ACHIEVEMENT_SUM,ATTACHMENT_NAME,RETURN_SUM,RETURN_AMOUNT,FILE_CHANGE_AMOUNT,USED_PRODUCT_NAME,RESPONSIBLE_PERSON_NAME,RESPONSIBLE_PERSON_ID,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,LATELY_TRADE_TIME,DELETE_TIME,RECOVERY_TIME,MODIFY_TAG,EXCEL_TAG,EXCEL_TAG2,EXCEL_TAG3,EXCEL_TAG4,DESIGN_MODULE_TAG,DESIGN_PROCEDURE_TAG,DESIGN_CELL_TAG,RECOMMEND_PROVIDER_TAG,PRICE_CHANGE_TAG,PRICE_ALARM_TAG,promotion,opinion,promotion2,opinion2,promotion3,opinion3,promotion4,opinion4) values('")).append(rsoo.getString("CHAIN_ID")).append("','").append(rsoo.getString("CHAIN_NAME")).append("','").append(rsoo.getString("PRODUCT_ID")).append("','").append(rsoo.getString("PRODUCT_NAME")).append("','").append(rsoo.getString("PRODUCT_NICK")).append("','").append(rsoo.getString("PRODUCT_CLASS")).append("','").append(rsoo.getString("TYPE")).append("','").append(rsoo.getString("AMOUNT_UNIT")).append("','").append(rsoo.getString("PRODUCT_DESCRIBE")).append("','").append(rsoo.getString("FACTORY_NAME")).append("','").append(rsoo.getString("FACTORY_ID")).append("','").append(rsoo.getString("PROVIDER_GROUP")).append("','").append(rsoo.getString("PHOTO1")).append("','").append(rsoo.getString("PHOTO2")).append("','").append(rsoo.getString("WARRANTY")).append("','").append(rsoo.getString("LIST_PRICE")).append("','").append(rsoo.getString("COST_PRICE")).append("','").append(rsoo.getString("REAL_COST_PRICE")).append("','").append(rsoo.getString("LIFECYCLE")).append("','").append(rsoo.getString("PERSONAL_UNIT")).append("','").append(rsoo.getString("PERSONAL_VALUE")).append("','").append(rsoo.getString("TWIN_NAME")).append("','").append(rsoo.getString("TWIN_ID")).append("','").append(rsoo.getString("REMARK")).append("','").append(rsoo.getString("CHECK_TAG")).append("','").append(rsoo.getString("ACHIEVEMENT_SUM")).append("','").append(rsoo.getString("ATTACHMENT_NAME")).append("','").append(rsoo.getString("RETURN_SUM")).append("','").append(rsoo.getString("RETURN_AMOUNT")).append("','").append(rsoo.getString("FILE_CHANGE_AMOUNT")).append("','").append(rsoo.getString("USED_PRODUCT_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_ID")).append("','").append(rsoo.getString("REGISTER")).append("','").append(rsoo.getString("CHECKER")).append("','").append(rsoo.getString("CHANGER")).append("','").append(rsoo.getString("REGISTER_ID")).append("','").append(rsoo.getString("CHECKER_ID")).append("','").append(rsoo.getString("CHANGER_ID")).append("','").append(rsoo.getString("REGISTER_TIME")).append("','").append(rsoo.getString("CHECK_TIME")).append("','").append(rsoo.getString("CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_TRADE_TIME")).append("','").append(rsoo.getString("DELETE_TIME")).append("','").append(rsoo.getString("RECOVERY_TIME")).append("','").append(rsoo.getString("MODIFY_TAG")).append("','").append(rsoo.getString("EXCEL_TAG")).append("','").append(rsoo.getString("EXCEL_TAG2")).append("','").append(rsoo.getString("EXCEL_TAG3")).append("','").append(rsoo.getString("EXCEL_TAG4")).append("','").append(rsoo.getString("DESIGN_MODULE_TAG")).append("','").append(rsoo.getString("DESIGN_PROCEDURE_TAG")).append("','").append(rsoo.getString("DESIGN_CELL_TAG")).append("','").append(rsoo.getString("RECOMMEND_PROVIDER_TAG")).append("','").append(rsoo.getString("PRICE_CHANGE_TAG")).append("','").append(rsoo.getString("PRICE_ALARM_TAG")).append("','").append(rsoo.getString("promotion")).append("','").append(rsoo.getString("opinion")).append("','").append(rsoo.getString("promotion2")).append("','").append(rsoo.getString("opinion2")).append("','").append(rsoo.getString("promotion3")).append("','").append(rsoo.getString("opinion3")).append("','").append(rsoo.getString("promotion4")).append("','").append(rsoo.getString("opinion4")).append("')").toString();
									design_db.executeUpdate(sqll);
								}
								String sql = (new StringBuilder("update design_file set chain_id='")).append(chain_id).append("',chain_name='").append(chain_name).append("',product_name='").append(product_name).append("',factory_name='").append(factory_name).append("',product_class='").append(product_class).append("',twin_name='").append(twin_name).append("',twin_ID='").append(twin_ID).append("',personal_unit='").append(personal_unit).append("',personal_value='").append(personal_value).append("',warranty='").append(warranty).append("',lifecycle='").append(lifecycle).append("',product_nick='").append(product_nick).append("',list_price='").append(list_price).append("',cost_price='").append(cost_price).append("',provider_group='").append(provider_group).append("',product_describe='").append(product_describe).append("',responsible_person_name='").append(responsible_person_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',amount_unit='").append(amount_unit).append("',changer_ID='").append(changer_ID).append("',changer='").append(changer).append("',change_time='").append(change_time).append("',lately_change_time='").append(lately_change_time).append("',file_change_amount='").append(change_amount).append("',promotion='").append(promotion).append("',check_tag='0',excel_tag='1' where product_ID='").append(product_ID).append("'").toString();
								design_db.executeUpdate(sql);
								sql = (new StringBuilder("delete from design_workflow where object_id='")).append(product_ID).append("'").toString();
								design_db.executeUpdate(sql);
								List rsList = GetWorkflow.getList(design_db, "design_config_workflow", "01");
								if (rsList.size() == 0)
								{
									sql = (new StringBuilder("update design_file set check_tag='1' where product_ID='")).append(product_ID).append("'").toString();
									design_db.executeUpdate(sql);
									sql = (new StringBuilder("delete from ecommerce_workflow where object_id='")).append(product_ID).append("' and type_id='01'").toString();
									design_db.executeUpdate(sql);
									List rsList1 = GetWorkflow.getList(design_db, "ecommerce_config_workflow", "01");
									if (rsList1.size() == 0)
									{
										sql = (new StringBuilder("update design_file set excel_tag='3' where product_ID='")).append(product_ID).append("'").toString();
										design_db.executeUpdate(sql);
									} else
									{
										for (Iterator ite = rsList1.iterator(); ite.hasNext(); design_db.executeUpdate(sql))
										{
											String elem[] = (String[])ite.next();
											sql = (new StringBuilder("insert into ecommerce_workflow(config_id,object_ID,describe1,describe2,type_id) values ('")).append(elem[0]).append("','").append(product_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("','01')").toString();
										}

									}
								} else
								{
									for (Iterator ite = rsList.iterator(); ite.hasNext(); design_db.executeUpdate(sql))
									{
										String elem[] = (String[])ite.next();
										sql = (new StringBuilder("insert into design_workflow(config_id,object_ID,describe1,describe2,type_id) values ('")).append(elem[0]).append("','").append(product_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("','01')").toString();
									}

								}
							}
							catch (Exception ex)
							{
								ex.printStackTrace();
							}
							response.sendRedirect((new StringBuilder("ecommerce/design/change_choose_attachment.jsp?product_ID=")).append(product_ID).toString());
						} else
						{
							response.sendRedirect((new StringBuilder("ecommerce/design/change_ok_a.jsp?product_ID=")).append(product_ID).toString());
						}
					} else
					{
						response.sendRedirect((new StringBuilder("ecommerce/design/change_ok_b.jsp?product_ID=")).append(product_ID).toString());
					}
				} else
				{
					response.sendRedirect("ecommerce/design/change_ok_c.jsp");
				}
				design_db.commit();
				design_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
